
package com.craterhill.java.ems.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.craterhill.java.ems.common.beans.GradingRules;
import com.craterhill.java.ems.dao.impl.AbstractDao;
import com.craterhill.java.ems.dao.utils.EMSResultSetExtractor;

public interface GradingRulesDao extends EMSDao<GradingRules> {

	public final String FIELD_LIST = "obj.grading_rules_id, obj.session_id, obj.from_marks, obj.to_marks, obj.grade" + AbstractDao.MONITER_FIELDS;

	public final String FIND_GRADING_RULES_BY_SESSION = "select " + FIELD_LIST + " from grading_rules obj where obj.session_id = ?";

	public final String SAVE_GRADING_RULES_PERIOD = "insert into grading_rules (session_id, from_marks, to_marks, grade, created_by) values (?, ?, ?, ?, ?)";
	public final String DELETE_GRADING_RULES_PERIOD = "delete from grading_rules where session_id = ?";

	public List<GradingRules> findBySession(final int sessionId);

	public boolean save(final int sessionId, final List<GradingRules> gradingRules);

	public final class GradingRulesExtractor extends EMSResultSetExtractor<GradingRules> {

		@Override
		protected GradingRules extractResultSetData(ResultSet resultSet) throws SQLException {
			GradingRules gradingRules = new GradingRules();
			gradingRules.setGradingRuleId(resultSet.getInt(1));
			gradingRules.setSessionId(resultSet.getInt(2));
			gradingRules.setFromMarks(resultSet.getInt(3));
			gradingRules.setToMarks(resultSet.getInt(4));
			gradingRules.setGrade(resultSet.getBoolean(5) ? 'P' : 'F');

			gradingRules.setStatus(resultSet.getBoolean(6));
			gradingRules.setCreatedBy(resultSet.getInt(7));
			gradingRules.setCreatedDate(resultSet.getDate(8));
			gradingRules.setModifiedDate(resultSet.getDate(9));
			return gradingRules;
		}
	}
}
